<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Utente</title>
<link rel="stylesheet" href="andreas08.css" type="text/css" media="screen,projection" />
<script type="text/javascript" src="../../../js/page.js"></script>
<script type="text/javascript">
function work(par){
    if(par == 2){
        if(!confirm("Sei sicuro di voler eliminare questo documento?"))
            return false;
    }
    /*
    controllo di validita' dei dati inseriti
    */
    var is_ok = true;
    var msg = "Ci sono degli errori nel form.\n";
    var list_index = 1;
    if(document.forms[0].progetto.value == 0){
    	msg += list_index+". Seleziona un progetto per il documento.\n";
    	document.getElementById("progetto").style.border = "1px solid #FF0000";
    	document.getElementById("t_prj").style.color = "#FF0000";
    	is_ok = false; 
    	list_index++;
    }
    else{
    	document.getElementById("progetto").style.border = "1px solid #eee";
    	document.getElementById("t_prj").style.color = "#003366";
    }
    if(trim(document.forms[0].titolo.value) == ""){
    	msg += list_index+". Seleziona un titolo per il documento.\n";
    	document.getElementById("titolo").style.border = "1px solid #FF0000";
    	document.getElementById("t_tit").style.color = "#FF0000";
    	is_ok = false;
    	list_index++;
    }
    else{
    	document.getElementById("titolo").style.border = "1px solid #eee";
    	document.getElementById("t_tit").style.color = "#003366";
    }
    if(document.forms[0].fname.value == ""){
    	msg += list_index+". Seleziona un file per il documento.\n";
    	document.getElementById("fname").style.border = "1px solid #FF0000";
    	document.getElementById("t_fna").style.color = "#FF0000";
    	is_ok = false;
    	list_index++;
    }
    else{
    	document.getElementById("fname").style.border = "1px solid #eee";
    	document.getElementById("t_fna").style.color = "#003366";
    }
    if(!is_ok){
    	alert(msg);
    	return false;
    }
    
    var leftS = (screen.width - 200) / 2;
    var topS = (screen.height - 180) / 2;
    document.forms[0]._i.value = <?php print $_i ?>;
    document.forms[0].funzione.value = par;
    document.forms[0].submit();
}

function categ(id){
	if(id == 2){
		/*
		nel caso si debbano gestire le categorie per piu' di un tipo, 
		occorre recuperarle usando ajax
		*/
		get_categories(id);
		//document.forms[0].categoria.disabled = false;
		document.forms[0].materia.disabled = false;
	}
	else{
		//document.forms[0].categoria.disabled = true;
		document.forms[0].materia.disabled = true;
	}
}

function get_categories(id){

}

</script>
</head>
<body <?php if(isset($msg)) print("onLoad=\"alert('".$msg."'); window.close(); window.opener.document.location.href='$referer'\"") ?> style="background-color: #ffffff">
    <p style="text-align: center; padding-left: 30px;  font-size: 12px; font-weight: bold">Gestione documenti</p>
    <form action="dettaglio_doc_progetto.php?upd=1" method="post" enctype="multipart/form-data" style="">
    <fieldset style="width: 550px; border: 1px solid; padding-top: 10px; margin-left: auto; margin-right: auto; margin-top: 20px">
    <legend style="font-weight: bold;">  Dati di base </legend>
    <table width="530">
        <tr>
            <td class="Titolo" align="left" style="color: #003366;width: 150px; padding-left: 10px; font-weight: bold">Tipo documento</td>
            <td style="width: 380px">
                <select name="tipo_documento" style="width: 380px; border: 1px solid ; font-size: 11px; ">
                	<option value="3">DP - Documenti relativi a progetti</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="height: 10px"></td>
        </tr>
        <tr>
            <td class="Titolo" id="t_prj" align="left" style="color: #003366;width: 150px; padding-left: 10px; font-weight: bold">Progetto</td>
            <td style="width: 380px">
                <select id="progetto" name="progetto" style="width: 380px; border: 1px solid ; font-size: 11px; ">
                	<option value="0">Seleziona un progetto</option>
                <?php
				while($prj = $res_projects->fetch_assoc()){
                ?>
                	<option <?php if($prj['id_progetto'] == $current_doc['progetto']) print ("selected='selected'") ?> value="<?php print $prj['id_progetto'] ?>"><?php print $prj['nome'] ?></option>
                <?php
				}
                ?>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="height: 10px"></td>
        </tr>
        <tr>
            <td class="Titolo" align="left" style="color: #003366;width: 150px; padding-left: 10px; font-weight: bold">Anno</td>
            <td style="width: 380px">
                <select name="anno" style="width: 380px; border: 1px solid ; font-size: 11px; ">
                <?php 
                while($anno = $res_anni->fetch_assoc()){
                ?>
                	<option value="<?php print $anno['id_anno'] ?>" <?php if($anno['id_anno'] == $current_doc['anno_scolastico']) print "selected='selected'" ?>><?php print $anno['descrizione']?></option>
                <?php 
                }
                ?>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;&nbsp;&nbsp;</td>
        </tr>
    </table>
    </fieldset>
    <fieldset style="width: 550px; border: 1px solid; padding-top: 10px; margin-top: 30px; margin-left: auto; margin-right: auto">
    <legend style="font-weight: bold"> Dati file </legend>
    <table width="530">
        <tr>
            <td class="Titolo" id="t_tit" align="left" style="color: #003366;width: 150px; padding-left: 10px; font-weight: bold">Titolo</td>
            <td style="width: 380px">
                <input type="text" id="titolo" name="titolo" style="width: 380px; font-size: 11px; border: 1px solid" value="<?php if(isset($current_doc)) print($current_doc['titolo']) ?>" />
            </td>
        </tr>
        <tr>
            <td colspan="2" style="height: 10px"></td>
        </tr>
        <tr>
            <td class="Titolo" align="left" style="color: #003366;width: 150px; padding-left: 10px; font-weight: bold">Abstract</td>
            <td style="width: 380px">
                <textarea name="abstract" style="width: 380px; height: 50px; font-size: 11px; border: 1px solid"><?php if(isset($current_doc)) print($current_doc['abstract']) ?></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="height: 10px"></td>
        </tr>
        <tr>
            <td class="Titolo" id="t_fna" align="left" style="color: #003366;width: 150px; padding-left: 10px; font-weight: bold">File</td>
            <td style="width: 380px">
            <?php if(isset($current_doc)){ ?>
            	<input type="text" id="fname" name="fname" class="file" style="width: 380px; font-size: 11px; border: 1px solid" value="<?php print $current_doc['file'] ?>"/>
            <?php }  else{ ?>
            	<div class="fileinputs" style="width: 380px">
                	<input type="file" id="fname" name="fname" class="file" style="width: 380px; font-size: 11px; border: 1px solid"/>
                </div>
            <?php } ?>
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;&nbsp;&nbsp;
            	<input type="hidden" name="funzione" />
			    <input type="hidden" name="_i" />
			    <input type="hidden" name="path" value="<?php if(isset($current_doc)) print $path ?>"/>
			    <input type="hidden" name="oldfile" value="<?php if(isset($current_doc)) print $current_doc['file'] ?>"/>
			    <input type="hidden" name="referer" value="<?php print $referer ?>" />
            </td>
        </tr>
    </table>
    </fieldset>
    <div style="margin-right: 40px; margin-top: 30px; width: 592px; text-align: right; padding-bottom: 40px">
        <a href="#" onclick="work(<?php if(isset($_REQUEST['_i']) && $_REQUEST['_i'] != 0) print("3"); else print("1"); ?>)" style="" >Registra</a>&nbsp;&nbsp;|&nbsp;&nbsp;
        <?php if(isset($_REQUEST['_i']) && $_REQUEST['_i'] != 0){
        ?>
        <a href="#" onclick="work(2)" >Elimina lavoro</a>&nbsp;&nbsp;|&nbsp;&nbsp;
        <?php
        }
        ?>
        <a href="#" onclick="window.close()" style="" >Chiudi</a>
    </div>
   </form>
</body>
</html>